<template>
	<view class="nearly-list-box" :style="{'height': `calc(100% - 100rpx - ${safeBottom}px)`}">
		<scroll-view class="nearly-list" scroll-y="true">
			<fix-item v-for="activity of activities" :activity="activity"></fix-item>
			<uni-load-more status="noMore"></uni-load-more>
			<view style="height: 60rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	import fixItem from './fixItem.vue'
	
	export default {
		name:"nearlyList",
		components: {
			fixItem
		},
		data() {
			return {
				activities: [],
				params: {
					lat: 0,
					lon: 0,
					pageSize: 50,
					pageNum: 1
				},
				safeBottom: 0
			};
		},
		mounted() {
			this.safeBottom = this.$safeBottom;
			this.params.lat = this.$myLocation.latitude;
			this.params.lon = this.$myLocation.longitude;
			this.getNearlyActivity('refresh');
			uni.$on('nearlyLikeActivity', (activity) => {
				let index = this.activities.findIndex(item => item === activity);
				if (index !== -1) {
					this.activities[index].isLike = true;
					this.activities[index].likeNum += 1;
				}
				
			})
		},
		methods: {
			getNearlyActivity(type) {
				this.$apis.getNearlyActivity(this.params).then(res => {
					if (res.code === 0) {
						this.activities = res.data.list;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.nearly-list-box {
		width: 100%;
		
		.nearly-list {
			width: 100%;
			height: 100%;
		}
	}
</style>